<?php


namespace Tbf\Bundle\YntAuthBundle\Douban;


use Symfony\Component\Routing\Router;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Tbf\Component\Path\PathFunction;

class Config {
    protected $app_key;
    protected $app_secret;
    protected $oauth2_auth_url = 'https://www.douban.com/service/auth2/auth';
    /** @var  Router */
    protected $router;
    protected $oauth2_token_url = 'https://www.douban.com/service/auth2/token';
    protected $api_url_base = 'https://api.douban.com';
    //所有RESTfull api此处包含http_method信息
    protected $api_map = array(
        'getCurrentUserInfo'=>array('/v2/user/~me','GET'),
        'share'=>array('/shuo/v2/statuses/','POST')//发送一条广播 我说 POST
    );
    function __construct($app_key,$app_secret,Router $router){
        $this->app_key = $app_key;
        $this->app_secret = $app_secret;
        $this->router = $router;
    }

    /**
     * @param mixed $app_key
     */
    public function setAppKey($app_key)
    {
        $this->app_key = $app_key;
    }

    /**
     * @return mixed
     */
    public function getAppKey()
    {
        return $this->app_key;
    }

    /**
     * @param mixed $app_secret
     */
    public function setAppSecret($app_secret)
    {
        $this->app_secret = $app_secret;
    }

    /**
     * @return mixed
     */
    public function getAppSecret()
    {
        return $this->app_secret;
    }

    /**
     * @param string $oauth2_auth_url
     */
    public function setOauth2AuthUrl($oauth2_auth_url)
    {
        $this->oauth2_auth_url = $oauth2_auth_url;
    }

    /**
     * @return string
     */
    public function getOauth2AuthUrl()
    {
        return $this->oauth2_auth_url;
    }
    public function getOauth2CallbackUrl(){
        return $this->router->generate('tbf_ynt_auth_callback_douban',array(),UrlGeneratorInterface::ABSOLUTE_URL);
    }

    /**
     * @param string $oauth2_token_url
     */
    public function setOauth2TokenUrl($oauth2_token_url)
    {
        $this->oauth2_token_url = $oauth2_token_url;
    }

    /**
     * @return string
     */
    public function getOauth2TokenUrl()
    {
        return $this->oauth2_token_url;
    }
    public function getApiData($name){
        $data = $this->api_map[$name];
        return array(
            'url'=>PathFunction::urlJoin($this->api_url_base,$data[0]),
            'http_method'=>$data[1]
        );
    }
}